import request from '@/utils/request'

//基础销售属性的某一个类型
export interface BaseSaleAttrItemType {
    id?: number,
    name: string
}
//基础销售属性列表的类型
export type BaseSaleAttrListType = BaseSaleAttrItemType[]



//spu图片列表的类型
export type SpuImageListType = SpuImgItemType[]

//spu销售属性值列表中的某一项的类型
export interface SpuSaleAttrValueItemType {
    baseSaleAttrId?: number,
    id?: number,
    isChecked?: string,
    saleAttrName?: string,
    saleAttrValueName: string,
    spuId?: number
}

// spu销售属性值列表的数据类型
export type SpuSaleAttrValueListType = SpuSaleAttrValueItemType[]

//某个spu的销售属性列表中的某一项类型
export interface SpuSaleAttrItemType {
    baseSaleAttrId?: number,
    id?: number,
    saleAttrName: string,
    spuId?: number,
    spuSaleAttrValueList: SpuSaleAttrValueListType,
    isEdit?:boolean,
    inputValue?:string
}

//spu销售属性列表类型
export type SpuSaleAttrListType = SpuSaleAttrItemType[]

//一个完整的spu信息的类型
export interface SpuInfoType {
    category3Id?: number | null,
    description: string,
    id?: number,
    tmId?: number|null,
    spuName: string,
    spuImageList: SpuImageListType|null,
    spuSaleAttrList: SpuSaleAttrListType|null,
}

//spu分页列表数据类型
export interface SpuListType {
    records: SpuInfoType[],
    total: number,
    size: number,
    current: number,
    searchCount: boolean,
    pages: number
}

//根据spuId请求回来的spu图片列表的某一项
export interface SpuImgItemType{
        id?: number,
        spuId?: number,
        imgName: string,
        imgUrl: string,
        name?: string;
        url?: string;
        response?: any;
}

//根据spuId请求回来的spu图片列表
export type SpuImgListType = SpuImgItemType[] 

//1.请求spu所有销售属性列表
export const requestBaseSaleAttrList = () => {
    return request.get<any, BaseSaleAttrListType>(`/admin/product/baseSaleAttrList`)
}


//2.根据spuId删除spu
export const requestDeleteSpu = (spuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`)
}

//3.新增spu
export const requestSaveSpuInfo = (spuInfo: SpuInfoType) => {
    return request.post<any, null>(`/admin/product/saveSpuInfo`, spuInfo)
}

//4.更新spu
export const requestUpdateSpuInfo = (spuInfo: SpuInfoType) => {
    return request.post<any, null>(`/admin/product/updateSpuInfo`, spuInfo)
}

//5.获取spu的分页列表
export const requestSpuList = (page: number, limit: number, category3Id: number) => {
    return request.get<any,SpuListType>(`/admin/product/${page}/${limit}?category3Id=${category3Id}`)
}

//6.根据spuId获取spu图片列表
export const requestSpuImgList = (spuId:number)=>{
    return request.get<any,SpuImgListType>(`/admin/product/spuImageList/${spuId}`)
}

//7.根据spuId获取当前spu的销售属性
export const requestSpuSaleAttrList = (spuId:number)=>{
    return request.get<any,SpuSaleAttrListType>(`/admin/product/spuSaleAttrList/${spuId}`)
}